﻿using MaterialDesignThemes.Wpf;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace GameView.Converts
{
    public class StatusToIconConverter : IValueConverter
    {
        // 状态码到图标和颜色的映射字典
        private static readonly Dictionary<int, (PackIconKind Icon, Brush Color)> StatusMap = new()
        {
            // 用户角色
            [1101] = (PackIconKind.Headset, Brushes.DodgerBlue),//客服
            [1102] = (PackIconKind.AccountCash, Brushes.MediumSeaGreen),//商人

            // 金额操作类型
            [4001] = (PackIconKind.PlusCircle, Brushes.ForestGreen),//增加
            [4002] = (PackIconKind.MinusCircle, Brushes.IndianRed),//扣除

            // 在线状态
            [6001] = (PackIconKind.LanConnect, Brushes.SeaGreen),//在线
            [6002] = (PackIconKind.LanDisconnect, Brushes.Red),//离线

            // 消息状态
            [2501] = (PackIconKind.EmailAlert, Brushes.Firebrick),//未读
            [2502] = (PackIconKind.EmailOpen, Brushes.DodgerBlue),//已读

            // 支付状态
            [2001] = (PackIconKind.ClockOutline, Brushes.DodgerBlue),//待付款
            [2002] = (PackIconKind.AlertCircleOutline, Brushes.OrangeRed),//账户异常
            [2003] = (PackIconKind.CheckBold, Brushes.ForestGreen),//已付款
            [2004] = (PackIconKind.Cancel, Brushes.DarkSlateGray),//已屏蔽
            [2005] = (PackIconKind.ClockOutline, Brushes.Orange),//待审核

            // 支付方式
            [5001] = (PackIconKind.CreditCard, Brushes.DodgerBlue),//支付宝
            [5002] = (PackIconKind.Wechat, Brushes.MediumSeaGreen),//微信
            [5003] = (PackIconKind.Bank, Brushes.DodgerBlue),//银联
            [5004] = (PackIconKind.DotsHorizontalCircle, Brushes.Violet),//其他

            // 操作结果
            [3001] = (PackIconKind.CheckCircle, Brushes.SeaGreen),//成功
            [3002] = (PackIconKind.CloseCircle, Brushes.Firebrick),//失败
            [3003] = (PackIconKind.Cancel, Brushes.DimGray),//取消
            [3004] = (PackIconKind.ClockOutline, Brushes.DodgerBlue),//已提交

            // 交易角色
            [7002] = (PackIconKind.AccountTie, Brushes.MediumSeaGreen),//商人
            [7003] = (PackIconKind.Account, Brushes.Teal),//玩家

            // 默认项
            [0] = (PackIconKind.HelpCircle, Brushes.DimGray)//未知
        };

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is not int statusCode)
                return GetDefaultValue(parameter);

            // 从字典获取值或返回默认
            if (!StatusMap.TryGetValue(statusCode, out var result))
                return GetDefaultValue(parameter);

            return parameter switch
            {
                "Icon" => result.Icon,
                "Color" => result.Color,
                _ => result // 返回元组
            };
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        private object GetDefaultValue(object parameter)
        {
            var defaultValue = StatusMap[0];
            return parameter switch
            {
                "Icon" => defaultValue.Icon,
                "Color" => defaultValue.Color,
                _ => defaultValue
            };
        }
    }
}